home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / bathtub.lua < prev    next >
Text File  |  2004-01-29  |  4KB  |  122 lines

  1. -- bathtub state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_bath", "bath");
  12.         button.addDescription(ACTIVITY, "bath");
  13.         -- button.addIcon("guiIconHygiene");
  14.         
  15.         if (this.getDirtiness() > 0.01) then 
  16.             button = addPieMenuButton("pm_clean", "clean");
  17.             button.addDescription(ACTIVITY, "clean");   
  18.             button.addDescription(ACTIVITY, "improveObjectTidiness");              
  19.             button.addIcon("guiIconWohnung");
  20.         end;
  21.         
  22.     end )
  23.     
  24.     onMsg("bath", function(msg)
  25.         -- get the game object server
  26.         local gameObjectServer = getGameObjectServer();
  27.         -- get character who initiated this action
  28.         local character = getStateObjectFromID(msg.sender);
  29.         -- if this is broken: abort characters action
  30.         if abortIfBroken(character) then return end;        
  31.         -- walk to the closest action point
  32.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"water1", "water2"});
  33.         --local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"water1", "water2"});
  34.         -- get the walk state object
  35.         local wso = character.walkSO;
  36.         if (actionPoint) then
  37.             -- create state machine contexts
  38.             local wsoContext = StateMachineContext();
  39.             -- store the action point
  40.             wsoContext.storeData("actionPointName", actionPoint.getName());
  41.             
  42.             if (wso.walkToActionPoint(actionPoint)) then
  43.                 wso.queueStateMachine("bathtubChar.openWater", this, wsoContext);
  44.             else
  45.                 print("no path found");
  46.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  47.                 --character.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
  48.                 --sendMsg("emoThink", wso);
  49.             end
  50.         else
  51.             print("no action point found");
  52.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  53.             --character.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  54.             --sendMsg("emoThink", wso);
  55.         end
  56.     end )
  57.     
  58.     
  59.     onMsg("clean", function(msg)
  60.         -- get the game object server
  61.         local gameObjectServer = getGameObjectServer();
  62.         -- get character who initiated this action
  63.         local character = getStateObjectFromID(msg.sender);
  64.         -- if this is broken: abort characters action
  65.         if abortIfBroken(character) then return end;
  66.         -- if character is too unhappy: abort characters action
  67.         if instantAbortIfUnhappy(character, "clean", this) then return end;
  68.         -- walk to the closest action point
  69.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"clean1", "clean2"});
  70.         --local actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"clean1", "clean2"});
  71.         -- get the walk state object
  72.         local wso = character.walkSO;
  73.         if (actionPoint) then
  74.             -- create state machine contexts
  75.             local wsoContext = StateMachineContext();
  76.             -- store the action point
  77.             wsoContext.storeData("actionPointName", actionPoint.getName());
  78.             
  79.             if (wso.walkToActionPoint(actionPoint)) then
  80.                 wso.queueStateMachine("bathtubChar.cleanStart", this, wsoContext);
  81.             else
  82.                 print("no path found");
  83.                 --queueNextClean(character);
  84.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  85.             end
  86.         else
  87.             print("no action point found");
  88.             --queueNextClean(character);
  89.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  90.         end
  91.     end )
  92.             
  93.     -- repair
  94.     onMsg("repair", function(msg)
  95.     
  96.         print("onMsg repair");
  97.         -- get character who initiated this action
  98.         local character = getStateObjectFromID(msg.sender);
  99.         -- walk to the closest action point
  100.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"repair1", "repair2"});
  101.         -- get the walk state object
  102.         local wso = character.walkSO;
  103.         if (actionPoint) then
  104.             -- create state machine contexts
  105.             local wsoContext = StateMachineContext();
  106.             -- store the action point
  107.             wsoContext.storeData("actionPointName", actionPoint.getName());
  108.             if (wso.walkToActionPoint(actionPoint)) then
  109.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  110.             else
  111.                 print("no path found");
  112.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  113.             end
  114.         else
  115.             print("no action point found");
  116.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  117.         end
  118.     end )
  119.         
  120.             
  121. endStateMachine()
  122.